﻿#region Librerias

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Net.Sockets;

#endregion


namespace ESF.SMTPServer
{
	public class SMTPRequest
	{
		#region Miembros
		
		public IPEndPoint ClientEndPoint;

		public string LastCommand;

		public SMTPSteps CurrentStep;

		public bool IsAuthenticated;

		// Indica que se uso EHLO en lugar de HELO
		public bool UsesESMTP;

		public string UserName;

		public string UserPassword;

		public long StreamLastPosition;

		#endregion


		#region Message Members

		public string HELO_ClientName;

		public string MAIL_From;

		public int MAIL_Size;

		public List<string> RCPTTO_Tos;

		public string DATA_Subject;

		public bool DATA_MessageIsBeginning;

		public StringBuilder DATA_TextMessage;

		public string DATA_MultipartBoundary;

		public List<string> DATA_Multiparts;

		public Dictionary<string, string> DATA_Descriptors;

		#endregion


		#region Propiedades

		public bool DATA_IsMultipartMixed
		{
			get
			{
				if (DATA_Descriptors.ContainsKey ("Content-Type"))
				{
					return DATA_Descriptors["Content-Type"].StartsWith ("multipart/mixed", StringComparison.InvariantCultureIgnoreCase);
				}

				return false;
			}
		}


		public bool DATA_IsMultipartAlternative
		{
			get
			{
				if (DATA_Descriptors.ContainsKey("Content-Type"))
				{
					return DATA_Descriptors["Content-Type"].StartsWith("multipart/alternative", StringComparison.InvariantCultureIgnoreCase);
				}

				return false;
			}
		}


		public bool DATA_IsTextPlain
		{
			get
			{
				if (DATA_Descriptors.ContainsKey("Content-Type"))
				{
					return DATA_Descriptors["Content-Type"].StartsWith("text/plain", StringComparison.InvariantCultureIgnoreCase);
				}

				return false;
			}
		}

		#endregion


		#region Constructor

		public SMTPRequest ()
		{
			IsAuthenticated = false;

			CurrentStep = SMTPSteps.START;

			RCPTTO_Tos = new List<string> ();

			DATA_TextMessage = new StringBuilder ();

			DATA_Descriptors = new Dictionary<string,string> ();

			DATA_Subject = string.Empty;

			StreamLastPosition = 0;

			DATA_MessageIsBeginning = true;

			DATA_Multiparts = new List<string> ();
		}

		#endregion
	}
}
